/*
 * @lc app=leetcode.cn id=20 lang=csharp
 *
 * [20] 有效的括号
 */

// @lc code=start
public class Solution {
    public bool IsValid(string s) {
        Stack<char> stack = new Stack<char>();
        List<char> left = new List<char> {'(','[','{'};
        foreach (var item in s)
        {
            if(left.Contains(item)) stack.Push(item);
            else if(stack.Peek()!=item) return false;
        }
        return true;
    }
}
// @lc code=end

